function ccR_Warlock_Curse_of_Enfeeblement(specNumber)
	if specNumber == nil then specNumber = ccrPlayerSpec() end
	local UseAbility = ccRS["Warlock_" .. specNumber .. "_UseCurseOfEnfeeblement"]	
	if UseAbility
	and SpellCanAttack(CURSE_OF_ENFEEBLEMENT)
	and not ccrTargetHasDebuff(CURSE_OF_ENFEEBLEMENT)
	then
		ccrCastAttack(CURSE_OF_ENFEEBLEMENT)
		return
	end
	return
end
function ccR_Warlock_Curse_of_the_Elements(specNumber)
	if specNumber == nil then specNumber = ccrPlayerSpec() end
	local UseAbility = ccRS["Warlock_" .. specNumber .. "_UseCurseOfTheElements"]	
	if UseAbility
	and SpellCanAttack(CURSE_OF_THE_ELEMENTS)
	and not ccrTargetHasDebuff(CURSE_OF_THE_ELEMENTS)
	then
		ccrCastAttack(CURSE_OF_THE_ELEMENTS)
		return
	end
	return
end
function ccR_Warlock_Havoc()
	if ccRS.Warlock_3_UseHavoc then
		-- Havoc on 2+ Targets
		if # tblPGetNearbyEnemies >= 2 then
			-- Havoc
			if SpellCanAttack(HAVOC) 
			and ccrValidTarget()
			then
				local obj = tblPGetNearbyEnemies
				for i = 1 , # obj do 
					if obj[i]
					and obj[i]:Exists()
					and not obj[i]:IsDead()
					and obj[i]:GetGUID() ~= Target:GetGUID()
					and obj[i]:IsInCombat()
					and obj[i]:GetCreatureInfo() ~= "Critter"
					and (obj[i]:IsTappedByPlayer() or (obj[i]:GetTarget():Exists() and obj[i]:GetTarget():GetName() == ccrPlayerName()))
					and obj[i]:InLineOfSight()
					then
						-- This isnt' our selected target so apply havoc
						obj[i]:CastSpellByName(GetSpellInfo(HAVOC))
						return
					end
				end
			end
		end
	end
	return
end
function ccR_Warlock_Switch_Away_From_Havoc()
	if ccrPlayerHasBuff(HAVOC)
	and ccrTargetHasDebuff(HAVOC)
	and ccrTargetHasDebuff(IMMOLATE)
	and ccrValidTarget()
	and # tblPGetNearbyEnemies >= 2
	then
		local obj = tblPGetNearbyEnemies
		for i = 1 , # obj do 
			local vSpell = {GetSpellInfo(HAVOC)}
			if obj[i]
			and obj[i]:Exists()
			and not obj[i]:IsDead()
			and obj[i]:GetGUID() ~= Target:GetGUID()
			and obj[i]:IsInCombat()
			and obj[i]:GetCreatureInfo() ~= "Critter"
			and (obj[i]:IsTappedByPlayer() or (obj[i]:GetTarget():Exists() and obj[i]:GetTarget():GetName() == ccrPlayerName()))
			and obj[i]:GetAura(vSpell[1]) == nil
			then
				-- This isnt' our selected target so apply havoc
				obj[i]:Target()
				return
			end
		end
	end
	return
end
function ccR_Warlock_Backlash()
	if ccrPlayerHasBuff(BACKLASH)
	and SpellCanAttack(INCINERATE)
	then
		ccrCastAttack(INCINERATE)
		return
	end
	return
end
function ccR_Warlock_Rain_of_Fire()
	-- Rain of Fire on AoE Groups
	local vCount = ccrTargetCount(12)
	if ccrPlayerHasSpell(RAIN_OF_FIRE)
	and vCount >= ccRS.Warlock_3_AoECount
	and ccrValidTarget()
	and (Target:GetDistance(Player) <= 34 and Target:InLineOfSight())
	then
		-- Player does not need to channel the spell, so just check for missing debuff
		if ccrPlayerHasSpell(AFTERMATH) 
		and not ccrTargetHasDebuff(RAIN_OF_FIRE)
		and SpellIsReady(RAIN_OF_FIRE)
		then
			ccrCast(RAIN_OF_FIRE)
			if SpellIsTargeting() == 1 then CastAtLocation(Target:GetLocation()) end
			return
		end
		-- Player needs to channel the spell
		if not ccrPlayerHasSpell(AFTERMATH) 
		and SpellIsReady(RAIN_OF_FIRE)
		and not ccrPlayerIsMoving()
		then
			ccrCast(RAIN_OF_FIRE)
			if SpellIsTargeting() == 1 then CastAtLocation(Target:GetLocation()) end
			return
		end
	end
	return
end
function ccR_Warlock_Corruption()
	if not ccrPlayerHasSpell(IMMOLATE)
	and not ccrTargetHasDebuff(CORRUPTION)
	and SpellCanAttack(CORRUPTION)
	then
		ccrCastAttack(CORRUPTION)
		return
	end
	return
end
function ccR_Warlock_Immolate()
	if ccrPlayerHasSpell(IMMOLATE) then
		-- Prevent double casting of Immolate
		if ccrTargetHasDebuff(IMMOLATE)
		and ccrPlayerIsCastingSpell(IMMOLATE)
		then
			SpellStopCasting();
		end
		-- Immolate
		if SpellCanAttack(IMMOLATE)
		and not ccrTargetHasDebuff(IMMOLATE)
		and not ccrPlayerIsMoving()
		then
			ccrCastAttack(IMMOLATE)
			return
		end
	end
	return
end
function ccR_Warlock_Ember_Tap()
	if specNumber == nil then specNumber = ccrPlayerSpec() end
	local UseAbility = ccRS["Warlock_" .. specNumber .. "_UseEmberTap"]	
	local AbilityHP = ccRS["Warlock_" .. specNumber .. "_EmberTapHP"]
	if UseAbility
	and SpellIsReady(EMBER_TAP)
	and ccrPlayerHealth() <= AbilityHP
	and ccrEmbers() >=1
	then
		if ccrPlayerIsCastingOrChanneling() then SpellStopCasting() end;
		ccrCast(EMBER_TAP)
		return
	end
	return	
end
function ccR_Warlock_Shadowburn()
	if ccrPlayerHasSpell(SHADOWBURN)
	and SpellCanAttack(SHADOWBURN)
	and ccrEmbers() >=1
	and ccrTargetHealth() <= 20
	then
		if ccrPlayerIsCastingOrChanneling() then SpellStopCasting() end;
		ccrCastAttack(SHADOWBURN)
		return
	end
	return
end
function ccR_Warlock_Fire_And_Brimstone()
	if SpellIsReady(FIRE_AND_BRIMSTONE)
	and not ccrPlayerHasBuff(FIRE_AND_BRIMSTONE)
	and ccrEmbers() >= 1
	then
		if ccrPlayerIsCastingOrChanneling() then SpellStopCasting() end;
		ccrCast(FIRE_AND_BRIMSTONE)
		return
	end
	return
end
function ccR_Warlock_Unending_Resolve()
	if specNumber == nil then specNumber = ccrPlayerSpec() end
	local UseAbility = ccRS["Warlock_" .. specNumber .. "_UseUnendingResolve"]	
	if UseAbility
	and SpellIsReady(UNENDING_RESOLVE) 
	then
		local x
		if # tblPGetNearbyEnemies > 0 then
			for x = 0, # tblPGetNearbyEnemies do
				local obj = tblPGetNearbyEnemies[x]
				if obj
				and obj:Exists()
				and (obj:GetTarget():Exists() and obj:GetTarget():GetName() == ccrPlayerName())
				then
					ccrCast(UNENDING_RESOLVE)
					return
				end
			end
		end
	end
end
function ccR_Warlock_Twilight_Ward()
	if specNumber == nil then specNumber = ccrPlayerSpec() end
	local UseAbility = ccRS["Warlock_" .. specNumber .. "_UseTwilightWard"]	
	if UseAbility
	and SpellIsReady(TWILIGHT_WARD) 
	then
		local x
		if # tblPGetNearbyEnemies > 0 then
			for x = 0, # tblPGetNearbyEnemies do
				local obj = tblPGetNearbyEnemies[x]
				if obj
				and obj:Exists()
				and (obj:GetTarget():Exists() and obj:GetTarget():GetName() == ccrPlayerName())
				then
					ccrCast(TWILIGHT_WARD)
					return
				end
			end
		end
	end
end